package com.gxa.modules.pc.hospital.controller;

import com.gxa.common.utils.Result;
import com.gxa.common.utils.TPage;
import com.gxa.modules.model.dto.DepartmentDTO;
import com.gxa.modules.model.entity.hospital.Department;
import com.gxa.modules.pc.hospital.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 科室表 前端控制器
 * </p>
 *
 * @author zhuiyi
 * @since 2022-11-13 05:39:52
 */
@RestController
@Api(tags = "科室接口")
@Slf4j
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @ApiOperation("查询所有  科室")
//    @RequiresPermissions("sys:user:list")  DepartmentDTO
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "departmentId",value = "科室id",dataType = "int"),
            @ApiImplicitParam(paramType = "query",name = "doctorName",value = "医生名字",dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "pageNum",value = "当前在那一页",dataType = "int"),
            @ApiImplicitParam(paramType = "query",name = "pageSize",value = "每页多少条记录",dataType = "int"),
            @ApiImplicitParam(paramType = "query",name = "orderField",value = "根据什么字段排序",dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "order",value = "升序-asc 降序-desc （不是asc都是降序）",dataType = "String"),
    })
    @GetMapping("/department/list")
    public Result list(@RequestParam @ApiIgnore HashMap<String,Object> searchMap){
        log.info("---------------{}-------------",searchMap);
        TPage tPage = departmentService.queryByPage(searchMap);
        return new Result().ok(tPage);
    }

    @PostMapping("/department/add")
    @ApiOperation("添加  科室")
    public Result add( @RequestBody DepartmentDTO dto){
        log.info("---------------{}-----{}--------",dto,dto);

        boolean save = this.departmentService.saveOne(dto);
        if (save){
            return new Result().ok();
        }
        return new Result().error();
    }
    @PutMapping("/department/update")
    @ApiOperation("修改  科室")
    public Result update( @RequestBody DepartmentDTO dto){
        log.info("---------------{}-----{}--------",dto.getDepartmentId(),dto);
        if(dto.getDepartmentId() == null){
            return new Result().error();
        }
        boolean update = this.departmentService.updateOne(dto);
        if (update){
            return new Result().ok();
        }
        return new Result().error();
    }

    @PostMapping("/department/del")
    @ApiOperation("批量删除也可单个删除:【1】  科室")
    public Result del( @RequestBody List<Integer> idList){
        log.info("---------------{}-----{}--------",idList,idList);
        boolean res = this.departmentService.removeByIds(idList);
        if (res){
            return new Result().ok();
        }
        return new Result().error();
    }
}
